#include "PlayerToken.h"
#include "../SGD Wrappers/CSGD_DirectInput.h"
#include "../SGD Wrappers/CSGD_Direct3D.h"
#include "../Tiles/BaseTile.h"

PlayerToken::PlayerToken(void)
{
	m_nTokenID = Player_Token;

	m_nHealth = 0;
	m_nStamina = 0;
	m_nDamage = 0;
	m_fSpeed = 0.0f;
	m_fJumpSpeed = 0.0f;
	m_fFireTimer = 0.0f;
	m_playerTestAnim = new Animation();

	this->m_playerTestAnim->Initialize();

}


PlayerToken::~PlayerToken(void)
{
	delete m_playerTestAnim;
}

void PlayerToken::Update( float fElapsedTime )
{
	
	CSGD_DirectInput* pIn = CSGD_DirectInput::GetInstance();
	
	if( pIn->KeyDown( DIK_W ) == true )
	{
		SetVelY( GetVelY() - m_fSpeed * fElapsedTime );
		
		this->m_playerTestAnim->Update(fElapsedTime);

	}

	if( pIn->KeyDown( DIK_S ) == true )
	{
		SetVelY( GetVelY() + m_fSpeed * fElapsedTime );
	}

	if( pIn->KeyDown( DIK_A ) == true )
	{
		SetVelX( GetVelX() - m_fSpeed * fElapsedTime );
	}

	if( pIn->KeyDown( DIK_D ) == true )
	{
		SetVelX( GetVelX() + m_fSpeed * fElapsedTime );
	}

	if( pIn->KeyDown( DIK_D ) == false && pIn->KeyDown( DIK_A ) == false && pIn->KeyDown( DIK_W ) == false && pIn->KeyDown( DIK_S ) == false )
	{
		SetVelX( 0.0f );
		SetVelY( 0.0f );
	}

	BaseToken::Update( fElapsedTime );
}

void PlayerToken::Render( void )
{
	

	CSGD_DirectInput* pIn = CSGD_DirectInput::GetInstance();
	
	if( pIn->KeyDown( DIK_W ) == true )
	{
		this->m_playerTestAnim->PlayAnimation(1.0f,true);

		m_playerTestAnim->Render((int)GetPosX(),(int)GetPosY(),false,1.0f, D3DCOLOR_XRGB(255,255,255));
	}
	else
		BaseToken::Render();
	

}

RECT PlayerToken::GetRect( void ) const
{
	return BaseToken::GetRect();
}

bool PlayerToken::CheckCollision( IBaseToken* pOther )
{
	if( BaseToken::CheckCollision( pOther ) == true )
	{
		if( pOther->GetTokenID() == Base_Tile )
		{
			switch( dynamic_cast< CBaseTile* >( pOther )->GetTileID() )
			{
			case 0: // Base Tile
				{
					SetVelX( -GetVelX() );
					SetVelY( -GetVelY() );
					break;
				}
			case 1: // Breakable Tile
				{
					SetVelX( -GetVelX() );
					SetVelY( -GetVelY() );
					break;
				}
			case 2: // Moveable Tile
				{
					SetVelX( -GetVelX() );
					SetVelY( -GetVelY() );
					break;
				}
			case 3: // Soft Tile
				{
					SetVelX( -GetVelX() );
					SetVelY( -GetVelY() );
					break;
				}
			case 4: // Spawn Tile
				{

				}
			case 5: // Trigger Tile
				{

				}
			}
		}
		
		return true;
	}

	return false;
}